﻿
using System.Security.Cryptography;
using System.Text;

namespace JshRCSWebApi.Util.DataAccess
{
    public class Md5Helper
    {
        public static string EncryptString(string str)
        {
            MD5 md5 = MD5.Create();

            // 将字符串转化为字节数组然后计算出字节数组的Hash
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            byte[] hashBytes = md5.ComputeHash(bytes);

            StringBuilder sb = new StringBuilder();
            foreach (byte hashByte in hashBytes)
            {
                sb.AppendFormat("{0:x2}", hashByte);
            }

            return sb.ToString();
        }
    }
}
